<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ログイン画面</title>
<style type="text/css">
table {
	margin-left: 50px;
	margin-top: 50px;
}

th {
	padding-bottom: 100px;
}

.user_id {
	padding-bottom: 60px;
}

.btn {
	width: 100px;
	height: 30px;
}

#id, #password {
	ime-mode: disabled;
}

#loginFail {
	
	size:5px;
	color: red;
	font-weight: bold;
}

</style>
<script type="text/javascript" src="/board/js/jquery-1.11.1.js"></script>
	
<script type="text/javascript">
$(document).ready(function(){
	
	$('#id').change(function(){
		var id = $('#id').val();
					
		for(var i = 0; i< id.length; ++i){
			var c = id.charCodeAt(i);
			if(c < 48 || c > 122){
				alert('全角は入力できません。');
				$('#id').val('');
				$('#id').focus();
				return;
			}
		}
	});
	
	$('#password').change(function(){
		var password = $('#password').val();
		
		for(var i = 0; i< password.length; ++i){
			var c = password.charCodeAt(i);
			if(c < 48 || c > 122){
				alert('全角は入力できません。');
				$('#password').val('');
				$('#password').focus();
				return;
			}
		}
	});
	
});


window.onload = function() {
	
	var login_id = '${session.id}';
	
	var login_status = '<s:property value="member.login_status" />';
	
	
	if(login_id.length != 0 && login_status.length != 0 && login_status == 0) {
		location.href='/board/member/goSetPassword.action';
	}
	
	else if(login_id.length != 0 && login_status.length != 0 && login_status == 1) {		
		
		location.href='/board/goMenu.action';
	}
	
	return;
} 

function formCheck() {
	
	var id = document.getElementById('id');
	var password = document.getElementById('password');
	
	if (id.value == '' || password.value == '') {
		alert('ユーザーIDとパスワードを入力してください。');
		return false;
	}
	
	if (id.value.length > 10 || password.value.length > 10) {
		alert('ユーザーIDとパスワードの桁数は10桁です。');
		return false;
	}
	
	return true;
	
}//formCheck()

function closeWindow() {
	
	this.close();
}//close()


</script>
</head>
<body>
	<s:form action="/board/member/login" method="post" theme="simple" onsubmit="javascript: return formCheck();">
		<table>
			<tr>
				<th>ログイン画面</th>
			</tr>
			<tr>
				<td class="user_id">ユーザーID</td>
				<td class="user_id"><s:textfield name="id" id="id" /></td>
			</tr>
			<tr>
				<td class="user_id">パスワード</td>
				<td class="user_id"><s:password name="password" id="password" /></td>
			</tr>
			<tr>
				<td></td>
				<td><s:submit class="btn" value="ログイン" /> <input type="button" class="btn" value="閉じる" onclick="javascript: closeWindow();"> </td>
			</tr>
			<tr>
				<td colspan="2"><s:if test="loginFail == true">
									<span id="loginFail">正しいユーザーIDとパスワードを入力してください。</span>
								</s:if>
				</td>
			</tr>			
		</table>
	</s:form>
	
</body>
</html>